package com.songyang.blog.config;

import com.songyang.blog.common.lang.Consts;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/*
因为上传的文件夹在项目外面不在resource里面，所以告诉spring外面的文件夹也是静态资源
 */
@Configuration
public class MVCConfig implements WebMvcConfigurer {
    @Autowired
    Consts consts;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/upload/avatar/**")
                .addResourceLocations("file:///" + consts.getUploadDir() + "/avatar/");
    }

    @Bean
    ModelMapper modelMapper() {//在searchservice里面用到，注入到springboot当中
        return new ModelMapper();
    }


}
